<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <base href="/">
    <link rel="stylesheet" href="../static/layui/css/layui.css">
    <script src="../static/js/jquery-3.2.1.min.js"></script>
    <script src="../static/layui/layui.js"></script>
    <script>
        $(function () {
            $("#btnClose").on("click", function () {
                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                parent.layer.close(index); //再执行关闭
            });

            $("#save").on("click",function () {
                var currentPassword = $("input[name='currentPassword']").val();
                var newPassword = $("input[name='newPassword']").val();
                var newPasswordRepeat = $("input[name='newPasswordRepeat']").val();
                if (newPassword != newPasswordRepeat){
                    layer.msg("两次输入的密码不一致");
                    return;
                }
                $.post({
                    url: "admin/password/update",
                    data:{
                        currentPassword: currentPassword,
                        newPassword:newPassword
                    },
                    success: function (result) {
                        if (result && result.success){
                            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            parent.layer.close(index); //再执行关闭
                        }else {
                            layer.msg(result.message);
                        }
                    }
                })
            })
        })
    </script>
</head>
<body>
    <div>
        <form class="layui-form model-form">
            <div class="layui-form-item">
                <label class="layui-form-label">原密码</label>
                <div class="layui-input-block">
                    <input name="currentPassword" placeholder="请输入正在使用的密码" type="password" class="layui-input" maxlength="20"
                           lay-verify="required" required/>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">新密码</label>
                <div class="layui-input-block">
                    <input name="newPassword" placeholder="请输入新密码" type="password" class="layui-input" maxlength="20"
                           lay-verify="required" required/>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">确认密码</label>
                <div class="layui-input-block">
                    <input name="newPasswordRepeat" placeholder="确认密码" type="password" class="layui-input" maxlength="20"
                           lay-verify="required" required/>
                </div>
            </div>

            <div class="layui-form-item model-form-footer" align="center">
                <!--<label class="layui-form-label"/></label>-->
                <button id="btnClose" class="layui-btn layui-btn-primary close" type="button">取消</button>
                <button class="layui-btn" lay-filter="userinfo-submit" lay-submit type="button" id="save">保存</button>
            </div>
        </form>
    </div>
</body>
</html>